// router.js
import {
	RouterMount,
	createRouter
} from 'uni-simple-router';
import store from "@/store"
const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});
//全局路由前置守卫
router.beforeEach(async (to, from, next) => {
	if(JSON.stringify(store.state.vuex_config) === '{}'){
		// console.log(uni);
		let res = await uni.$u.api.config();
		if(res.code){
			store.commit('set', {
				name: 'vuex_config',
				value: res.data
			})
		}
	}
	if (to.meta.auth && !store.state.vuex_token) {
		store.commit('set', {name: 'pre_login_page',value: from.path + uni.$u.queryParams(from.query) });
		return next({
			path: '/pages/login/login',
			NAVTYPE: 'push'
		});
	}
	next();
});
// 全局路由后置守卫
router.afterEach((to, from) => {})
export {
	router,
	RouterMount
}
